﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Snowdreamist.Collection.Tree;

namespace Snowdreamist.Text.UBB
{
    /// <summary>
    /// UBBElement, all ubb elements' base class
    /// </summary>
    public abstract class UBBElement : TreeNodeBase<UBBElement>, ICloneable
    {
        public UBBElement(string labelName)
        {
            this.LabelName = labelName;
        }

        /// <summary>
        /// LabelName (without parameters)
        /// </summary>
        public string LabelName { get; private set; }

        /// <summary>
        /// Get ubb code
        /// </summary>
        /// <returns></returns>
        public virtual string SerializeToUBBCode()
        {
            return this.LabelName;
        }

        public override int GetHashCode()
        {
            return this.GetType().GetHashCode();
        }

        public override void ToString(int indent, StringBuilder strBuilder)
        {
            if (indent != 0)
                strBuilder.Append(new string('\t', indent));
            strBuilder.Append('[');
            strBuilder.Append(this.SerializeToUBBCode());
            strBuilder.Append(']');
            strBuilder.Append('\n');
            base.ToString(indent, strBuilder);
        }

        protected void SkipToString(int indent, StringBuilder strBuilder)
        {
            base.ToString(indent, strBuilder);
        }

        /// <summary>
        /// Clone a same element
        /// </summary>
        /// <returns></returns>
        public abstract object Clone();

        protected override ITreeNodeCollection<UBBElement> CreateCollection()
        {
            return new UBBElementCollection(this);
        }
    }
}